#!/bin/bash

if [ -z "$1" ]; then
	headers="*.hh *h"
else
	headers="$@"
fi

for i in $headers; do
	if [ ! -f $i ]; then
		continue;
	fi

	name=${i%.hh}
	name=${name%.h}

	files="$i"

	echo "$name"

	if [ -f "$name.cc" ]; then
		files="$files $name.cc"
	fi

	if [ -f "$name.c" ]; then
		files="$files $name.c"
	fi

	$(dirname "$0")/../../scripts/cldoc-dev generate -- --quiet --output html $files

	for x in html/xml/*.xml; do
		cp $x ../output/$name-${x#html/xml/}
	done

	rm -rf html

	echo "$name (static)"

	$(dirname "$0")/../../scripts/cldoc-dev generate -- --quiet --output static --static $files

	for x in static/*.html; do
		cp $x ../output/$name-${x#static/}.static
	done

	rm -rf static
done
